package sg.edu.nus.iss.club;
import java.io.Serializable;

public class Person implements Comparable <Person>,Serializable {
	private String surName;
	private String firstName;
	private String secondName;
	
	
	public Person (String surName, String firstName, String secondName) { //constructor
		this.surName = surName;
		this.firstName = firstName;
		this.secondName = secondName;
		
	}
	
	public Person (String surName, String firstName) { //extra constructor without secondName
		this.surName = surName;
		this.firstName = firstName;
		this.secondName = null;
		
	}
	
	public String toString() {
		String result = surName + " " + firstName;
		if (secondName !=null) {
			result += " " +secondName;
		}
		return result;
	}
	
	public void show () {
		
		System.out.println(this.toString());
	}
	
	
	public String getSurName() {
		return surName;
	}

	public void setSurName(String surName) {
		this.surName = surName;
	}

	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public String getSecondName() {
		return secondName;
	}

	public void setSecondName(String secondName) {
		this.secondName = secondName;
	}
	
	public int compareTo(Person p2) {
		if (p2 == null){
			return -1;
		}

		if (surName.compareTo(p2.surName) == 0) {
			
			if (firstName.compareTo(p2.firstName) == 0) {
				
				if (secondName == null && p2.secondName == null){
					return 0;
				}else if (secondName !=null && p2.secondName == null){
					return 1;
				}else if (secondName == null && p2.secondName != null){
					return -1;
				}else {
					return secondName.compareTo(p2.secondName);
				}
				
			}else{
				return firstName.compareTo(p2.firstName);
			}
		}else {
			return surName.compareTo(p2.surName);
		}
		
	}
	
	public boolean equals (Object p2) {
		if (p2 instanceof Person){
			if (compareTo((Person)p2)==0 ){
				return true;
			}else {
				return false;
			}
		}else {
			return false;
		}
		
	}

}
